package com.example.opengl.ui.first;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider;

import com.example.opengl.R;
import com.example.opengl.databinding.FragmentPageFirstBinding;
import com.example.opengl.ui.first.triangle.TriangleActivity;

/**
 * A placeholder fragment containing a simple view.
 */
public class PageFirstFragment extends Fragment implements View.OnClickListener {

    private PageFirstViewModel pageViewModel;
    private FragmentPageFirstBinding binding;

    public static PageFirstFragment newInstance() {
        PageFirstFragment fragment = new PageFirstFragment();
        Bundle bundle = new Bundle();
        fragment.setArguments(bundle);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        pageViewModel = new ViewModelProvider(this,
                new ViewModelProvider.NewInstanceFactory()).get(PageFirstViewModel.class);
    }

    @Override
    public View onCreateView(
            @NonNull LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        //===
        binding = FragmentPageFirstBinding.inflate(inflater, container, false);
        View root = binding.getRoot();
        //===
        binding.btnTriangleJava.setOnClickListener(this);
        binding.btnTriangleNative.setOnClickListener(this);
        //===
        return root;
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        binding = null;
    }

    @Override
    public void onClick(View v) {
        if (v.getId() == R.id.btn_triangle_java) {
            Intent intent = new Intent(getActivity(), TriangleActivity.class);
            intent.putExtra(TriangleActivity.TYPE_NAME, TriangleActivity.TYPE_JAVA);
            startActivity(intent);
        } else if (v.getId() == R.id.btn_triangle_native) {
            Intent intent = new Intent(getActivity(), TriangleActivity.class);
            intent.putExtra(TriangleActivity.TYPE_NAME, TriangleActivity.TYPE_NATIVE);
            startActivity(intent);
        }
    }
}